/*
 * Copyright 2016 drakeet. https://github.com/drakeet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.epfresh.adapter;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.bean.OfferGoodsGo;
import com.epfresh.bean.MarketBean;

import java.util.Collections;
import java.util.List;

import multitype.OnRecyclerViewItemClickListener;

/**
 * @author drakeet
 */
public class OfferGoTopCategoryItemAdapter extends RecyclerView.Adapter<OfferGoTopCategoryItemAdapter.ViewHolder>  implements View.OnClickListener{
    String[] colorsBack = {"#24af75","#ffffff"};
    String[] colorsTitle = {"#ffffff","#343434"};
    String categoryId = "";
    @Override
    public void onClick(View v) {
        Object o = v.getTag(R.id.item_key_status);
        
        if (onRecyclerViewItemClickListener != null && o instanceof OfferGoodsGo.TopCategoryBean) {
            onRecyclerViewItemClickListener.onItemClick(v, 0, o);
        }
    }
    private List<OfferGoodsGo.TopCategoryBean> posts = Collections.emptyList();
    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;

    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }


    public void setPosts(@NonNull List<OfferGoodsGo.TopCategoryBean> posts) {
        this.posts = posts;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.include_market_category_top, parent, false);
        return new ViewHolder(view);
    }



    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        OfferGoodsGo.TopCategoryBean bean = posts.get(position);
        if(true)/*根据是否是本类型进行展示，最后由后端去掉数据*/


        holder.tv_top_category_title.setText(bean.getName());
        holder.tv_top_category_title.setTag(R.id.item_key_status,bean);
        holder.tv_top_category_title.setOnClickListener(this);
        GradientDrawable myGrad = (GradientDrawable)holder.tv_top_category_title.getBackground();
        if(bean.isSelect()) {
            myGrad.setColor(Color.parseColor(colorsBack[0]));
            holder.tv_top_category_title.setTextColor(Color.parseColor(colorsTitle[0]));
        }
        else {
            myGrad.setColor(Color.parseColor(colorsBack[1]));
            holder.tv_top_category_title.setTextColor(Color.parseColor(colorsTitle[1]));
        }
        if(bean.getNumber()!=0){

        }else {

        }
    }

    @Override
    public int getItemCount() {
        return posts.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tv_top_category_title;

        ViewHolder(View itemView) {
            super(itemView);
            tv_top_category_title = (TextView) itemView.findViewById(R.id.tv_top_category_title);
        }
    }
}
